<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Mage
 * @package     Mage_Catalog
 * @copyright   Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */


/**
 * Product description block
 *
 * @category   Mage
 * @package    Mage_Catalog
 * @author     Magento Core Team <core@magentocommerce.com>
 */
class Mage_Catalog_Block_Product_View_TabNew extends Mage_Catalog_Block_Product_Abstract
{
    protected $_product = null;

    function getProduct()
    {
        if (!($this->getData('product') instanceof Mage_Catalog_Model_Product)) {
            $this->setData('product', Mage::registry('product'));
        }
        return $this->getData('product');
    }
	  public function getToolbarHtml()
    {
        return $this->getChildHtml('toolbar');
    }
      public function productAttribute($product, $attributeHtml, $attributeName)
    {   
        $attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeName);
        if ($attribute && $attribute->getId() && ($attribute->getFrontendInput() != 'media_image')
            && (!$attribute->getIsHtmlAllowedOnFront() && !$attribute->getIsWysiwygEnabled())) {
                if ($attribute->getFrontendInput() != 'price') {
                    $attributeHtml = $this->escapeHtml($attributeHtml);
                }
                if ($attribute->getFrontendInput() == 'textarea') {
                    $attributeHtml = nl2br($attributeHtml);
                }
        }
        if ($attribute->getIsHtmlAllowedOnFront() && $attribute->getIsWysiwygEnabled()) {
            if (Mage::helper('catalog')->isUrlDirectivesParsingAllowed()) {
                $attributeHtml = $this->_getTemplateProcessor()->filter($attributeHtml);
            }
        }

        $attributeHtml = $this->process('productAttribute', $attributeHtml, array(
            'product'   => $product,
            'attribute' => $attributeName
        ));

        return $attributeHtml;
    }

  
    public function getdataproductview($productid)
    {
          $resource = Mage::getSingleton('core/resource');
               $readConnection = $resource->getConnection('core_read');
               $table = $resource->getTableName('catalog/product');
               $table_review_detail= $resource->getTableName('review/review_detail');//get title,detail,nickname, customerid
               $table_review= $resource->getTableName('review/review');//get created on // review_id
               $table_review_status= $resource->getTableName('review/review_status');//get status_code
               $table_review_entity=$resource->getTableName('review/review_entity');//get entity_id, entity_code
               $table_review_store = $resource->getTableName('review/review_store');//get review_id, store_ID
              // $productId = $this->getRequest()->getParam('id');
                             
                //get name
               
                $model = Mage::getModel('catalog/product'); //getting product model
                $_product = $model->load($productid); //getting product object for particular product id
//            echo "product name : ";
//            echo $_product->getName().'<br/>'; //product name
                //SELECT p.sku FROM `catalog_product_entity` p join `review`  r on r.entity_pk_value = p.entity_id WHERE p.entity_id = 1
                //SELECT p.sku FROM `catalog_product_entity` p join `review`  r on r.entity_pk_value = p.entity_id ,`review` ri join `review_detail` rdt on ri.entity_id = rdt.review_id WHERE p.entity_id = 1
                 $query = 'SELECT count(r.review_id), r.review_id,r.created_at,rdt.title,rdt.customer_id, rdt.detail, rdt.nickname,rs.status_code, p.sku FROM ' . $table_review . ' r join ' .$table_review_store .
                  ' rvs on r.review_id = rvs.review_id  join ' .$table_review_detail. ' rdt on r.review_id = rdt.review_id join review_status rs on r.status_id = rs.status_id join '.$table.' p on r.entity_pk_value = p.entity_id '                  
                  . ' WHERE p.entity_id = '. (int)$productid 
                  .' Group By r.review_id'
                  .' Order By r.Review_ID DESC LIMIT 0 , 20 '
             ;
                
//            $data = Mage::getSingleton('core/resource') ->getConnection('core_read')->mysql_num_rows($query); 
//            echo 'row :'. $data;
//            while($row = mysql_fetch_array($data)){
//                echo "There are ". $row['COUNT(value_id)'] ." ". $row['value'] ." items.";
//                    echo "<br />";
//                } 
//                 $result = $readConnection->mysql_query($query) or die(mysql_error());
//              $total_row=mysql_num_rows($result);
//                 echo '$total_row :'. $total_row ;
             $sku = $readConnection->fetchAll($query);
          
           return $sku;
    }
    public function getnameproduct($productid)
    {
        $model = Mage::getModel('catalog/product');
        $_productname = $model->load($productid);
        return $_productname;
    }
}
